A small shell function to open files from WSL2 using native Windows apps
2026-01-27
One-Sentence Summary. Open images and any other files from the WSL2 terminal directly in their native Windows applications.
Abstract. Working in WSL2 often breaks simple workflows like opening images or PDFs from the terminal. This article presents a minimal, reliable shell function that opens any file from WSL2 using Windows Explorer, avoiding common issues with UNC paths and unreliable direct application launches.
Keywords. WSL2, Windows Subsystem for Linux, zsh, bash, Windows, productivity, developer tools
WSL2 is fantastic.
But the moment you try to open an image from the terminal, everything falls apart.
You try:
explorer.exe image.pngNothing happens. Or Explorer opens the wrong folder. Or Windows throws a cryptic UNC-path error.
Let’s fix this properly — with one small, reliable function.
To open any file from WSL2 in its Windows environment, add one small shell function to your config file.
⚠️ Limitation: this works on real paths only (no symbolic links).
Open your shell config file:
~/.zshrc~/.bashrcPaste this function:
winopen() {
explorer.exe "$(wslpath -w "$(realpath "$1")")"
}
source ~/.zshrc # or: source ~/.bashrc
winopen image.pngDone.
Edit your config file:
vim ~/.zshrcAdd this one-liner anywhere:
winopen() {
explorer.exe "$(wslpath -w "$(realpath "$1")")"
}The same function works in Bash.
Add it to ~/.bashrc:
winopen() {
explorer.exe "$(wslpath -w "$(realpath "$1")")"
}On Unix-like systems with a GUI, the equivalent is trivial:
open file.png # macOS
xdg-open file.png # Linux desktopWSL2 is special because it crosses OS boundaries.
Reload your shell:
source ~/.zshrc # or source ~/.bashrcThen:
winopen image.png
winopen file.pdf
winopen video.mp4Windows Explorer opens at the correct location.
Select the file. Hit Enter.
The file opens using the default Windows application.
WSL2 runs Linux in a VM. That means:
\\wsl.localhost\Ubuntu-22.04\home\username\...So even when a command looks correct, it often fails silently.
This is not user error. It’s impedance mismatch.
Windows Explorer:
Explorer is the stable bridge between WSL and Windows.
WSL–Windows integration has multiple layers:
| Goal | Tool | Reliability |
|---|---|---|
| Browse WSL files | Windows Explorer | ✅ Always |
| Open via Enter | Explorer | ✅ Always |
| Open directly in app | App-dependent | ⚠️ |
| Guaranteed native paths | /mnt/c |
✅ |
Once you use the right layer, the problem disappears.
/home/.../mnt/c only if you need guaranteed
direct app launchesSimple. Honest. Reliable.
This function is tiny.
But it removes a constant friction point when working in WSL2: previewing images, checking PDFs, opening generated files.
One command. Any file. Native Windows apps.
Honestly, this one made me smile when it finally clicked — fewer hacks, less friction, and a smoother dev loop always feels good 😊
✅ 100% vibe-code certified 💯
DOI: